*** Table 2 ***	

use "$data/simulated_df.dta", clear 

********************************************************************************
*** Main regressions ***
********************************************************************************

est clear 
foreach var in any_post_total_fpds_over50k ///
	any_post_total_patent any_post_total_hi_orig  ///
	post_any_vc ///
	any_post_total_allsbir_diff any_post_total_hi_cite {
		
		if "`var'"=="any_post_total_patent" {
			local stub "pat"
			local head "Patent"
			local yr "1095"
		}
		if "`var'"=="any_post_total_fpds_over50k" {
			local stub "fpds"
			local head "Non-SBIR Contract"
			local yr "1095"
		}
		if "`var'"=="post_any_vc" {
			local stub "vc"
			local head "VC"
			local yr "1095"
		}
		if "`var'"=="any_post_total_hi_orig" {
			local stub "orig"
			local head "High Originality"
			local yr "1095"
		}
		if "`var'"=="any_post_total_allsbir_diff" {
			local stub "allsbir"
			local yr ""
		}
		if "`var'"=="any_post_total_hi_cite" {
			local stub "cite"
			local yr "1095"
		}
		 
		
		di "`var'"
		
		qui eststo `stub'1: areg `var'`yr' i.select##i.open $rddmain_controls ///
			[aweight=weight] if $open_first & pre_total_allsbir==0 | ///
				$conv17_first & pre_total_allsbir==0, ///
			cluster(topic_n) absorb(topic_n)
		estadd scalar R= e(r2): `stub'1
		estadd local pd "2017-19": `stub'1
		estadd local prop "First": `stub'1
		estadd local controls "No": `stub'1
		estadd local techfe "No": `stub'1
		qui sum `var'`yr' if $open_first & pre_total_allsbir==0 | ///
				$conv17_first & pre_total_allsbir==0
		estadd scalar ymean = r(mean): `stub'1
		
		qui eststo `stub'3: areg `var'`yr' i.select##i.open $rddmain_controls ///
			employees_at_app age i.full_tag_n25 [aweight=weight] ///
			if $open_first & pre_total_allsbir==0 | ///
				$conv17_first & pre_total_allsbir==0, ///
			cluster(topic_n) absorb(topic_n)
		estadd scalar R= e(r2): `stub'3
		estadd local pd "2017-19": `stub'3
		estadd local prop "First": `stub'3
		estadd local controls "Yes": `stub'3
		estadd local techfe "Yes": `stub'3
		qui sum `var'`yr' if $open_first & pre_total_allsbir==0 | ///
				$conv17_first & pre_total_allsbir==0
		estadd scalar ymean = r(mean): `stub'3	
				
		qui eststo `stub'4: areg `var'`yr' i.select##i.open $rddmain_controls ///
			employees_at_app age i.full_tag_n25 [aweight=weight] ///
			if $open_all | $conv_all , ///
			cluster(topic_n) absorb(topic_n)
		estadd scalar R= e(r2): `stub'4
		estadd local pd "2003-19": `stub'4
		estadd local prop "All": `stub'4
		estadd local controls "Yes": `stub'4
		estadd local techfe "Yes": `stub'4
		qui sum `var'`yr' if $open_all | $conv_all 
		estadd scalar ymean = r(mean): `stub'4
		
	}
	
esttab fpds1 vc1 pat1 orig1 allsbir1 using "$tables/table2a.tex", ///
	$general $labels ///
	keep(1.select 1.select#1.open) ///
	scalars("controls Lifecycle Controls" "techfe Narrow Tech FE" "prop Proposal" ///
		    "pd Time Period" "ymean Outcome Mean") ///
	postfoot("\midrule \end{tabular} \end{footnotesize} \\ ") ///
	prehead("\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{footnotesize} \begin{tabular}{l*{5}{>{\centering\arraybackslash}p{0.09\textwidth}}}  \toprule \\ \multicolumn{6}{c}{Panel A: Baseline Specification} \\ \\ & \multicolumn{1}{c}{$\mathbbm{1}$(DoD} & \multicolumn{1}{c}{\multirow{2}{*}{$\mathbbm{1}$(VC)}} & \multicolumn{1}{c}{\multirow{2}{*}{$\mathbbm{1}$(Patent)}} & \multicolumn{1}{c}{$\mathbbm{1}$(High} & \multicolumn{1}{c}{$\mathbbm{1}$($> 1$} \\ & \multicolumn{1}{c}{Contract)} & & & \multicolumn{1}{c}{Orig Pat)} & \multicolumn{1}{c}{SBIR)} \\ \cmidrule(lr){2-2}  \cmidrule(lr){3-3}  \cmidrule(lr){4-4} \cmidrule(lr){5-5} \cmidrule(lr){6-6} ")

esttab fpds3 vc3 pat3 orig3 allsbir3 using "$tables/table2b.tex", ///
	$general $labels ///
	keep(1.select 1.select#1.open) ///
	scalars("controls Lifecycle Controls" "techfe Narrow Tech FE" "prop Proposal" ///
		    "pd Time Period" "ymean Outcome Mean") ///
	postfoot("\midrule \end{tabular} \end{footnotesize} \\ ") ///
	prehead("\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{footnotesize} \begin{tabular}{l*{5}{>{\centering\arraybackslash}p{0.09\textwidth}}} \\ \multicolumn{6}{c}{Panel B: Controls and Technology Fixed Effects} \\ \\ ")

esttab fpds4 vc4 pat4 orig4 allsbir4 using "$tables/table2c.tex", ///
	$general $labels ///
	keep(1.select 1.select#1.open) ///
	scalars("controls Lifecycle Controls" "techfe Narrow Tech FE" "prop Proposal" ///
		    "pd Time Period" "ymean Outcome Mean") ///
	postfoot("\bottomrule \end{tabular} \end{footnotesize} \\ ") ///
	prehead("\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{footnotesize} \begin{tabular}{l*{5}{>{\centering\arraybackslash}p{0.09\textwidth}}} \\ \multicolumn{6}{c}{Panel C: All Proposals} \\ \\ ")
